/*
 * ESBlueBox.java
 *
 * Created on December 29, 2007, 12:49 PM
 *
 * Copyright (C) 2007-2008  Hylke van der Schaaf
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, in version 3 of the License.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */
package hextd.sprite;

import hextd.util.Cache;
import hextd.util.Geometry;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.AffineTransform;

/**
 *
 * @author hylke
 */
public class ESBlueBox extends EnemySpriteBase {

	private int prevPaintTime;
	private Color bodyColor = new Color(50, 50, 255);
	private Stroke bodyStroke;
	private Shape[] bodyShapes;
	private int bodyStep = 0;
	private static String infoText =
			"<h1>Blue Box</h1>" +
			"<p>" +
			"It's a box, and it's blue.<br>" +
			"That means it's vulnerable to blue towers, and resistant agains yellow towers." +
			"</p>";

	/**
	 * Creates a new instance of ESBlueBox
	 */
	public ESBlueBox() {
		super("Blue Box");
		this.damageColor = EnemySprite.COLOR.BLUE;
		this.damageColorAnti = EnemySprite.COLOR.YELLOW;
	}

	public String getInfoString() {
		return this.infoText +
				"<p>" + super.getInfoString() + "</p>";
	}

	public void resetScale() {
		super.resetScale();
		Cache cache = this.context.getCache();

		if (cache.hasShapeArr("ESBBShapes" + this.size.letter)) {
			this.bodyShapes = cache.getShapeArr("ESBBShapes" + this.size.letter);
		} else {
			this.bodyShapes = new Shape[16];

			double dr = 2.0 * Math.PI / 16;
			double r = 0;
			for (int i = 0; i < this.bodyShapes.length; i++) {

				float scale = this.context.paintScale * this.size.scaleMod;
				float[][] points = {
					{+scale * (5.5f + (float) Math.sin(+r)) / 24, +scale * (5.5f + (float) Math.cos(+r)) / 24},
					{+scale * (5.5f + (float) Math.cos(-r)) / 24, -scale * (5.5f + (float) Math.sin(-r)) / 24},
					{-scale * (5.5f + (float) Math.sin(-r)) / 24, -scale * (5.5f + (float) Math.cos(-r)) / 24},
					{-scale * (5.5f + (float) Math.cos(+r)) / 24, +scale * (5.5f + (float) Math.sin(+r)) / 24}
				};
				this.bodyShapes[i] = Geometry.coordsToGeneralPath(points, true);
				r += dr;
			}
			cache.putShapeArr("ESBBShapes" + this.size.letter, this.bodyShapes);
		}
		this.bodyStroke = new BasicStroke(2.5f * this.context.strokeScale, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER);
	}

	public void paint(Graphics2D g2, int gameTime) {
		if (this.inactive || this.dead) {
			this.prevPaintTime = gameTime;
		} else {
			Stroke defaultStroke = g2.getStroke();
			this.bodyStep += gameTime - this.prevPaintTime;
			if (this.bodyStep >= this.bodyShapes.length) {
				this.bodyStep = 0;
			}
			this.prevPaintTime = gameTime;

			AffineTransform saveXform = g2.getTransform();
			g2.transform(atTranslate);

			if (this.shielded) {
				this.paintShield_bottom(g2);
			}
			this.paintHealthLine(g2);

			g2.setColor(this.bodyColor);
			g2.setStroke(this.bodyStroke);
			g2.draw(this.bodyShapes[this.bodyStep]);
			g2.setTransform(saveXform);

			if (this.shielded) {
				g2.transform(atTranslate);
				this.paintShield_top(g2);
				g2.setTransform(saveXform);
			}
			
			super.paintSelected(g2);

			g2.setStroke(defaultStroke);
		}
	}
}
